package com.novabluetooth.adapter;

import java.util.List;

import com.health.R;
import com.health.tablebean.BTDevice;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BlueToothDeviceAdapter extends BaseAdapter {

	private List<BTDevice> infoList;
	private Context context;
	
	public BlueToothDeviceAdapter(Context context,List<BTDevice> infoList) {
		super();
		this.context = context;
		this.infoList = infoList;
	}
	
	

	public void setInfoList(List<BTDevice> infoList) {
		this.infoList = infoList;
	}



	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView ==null) {
			convertView = View.inflate(context, R.layout.bluetooth_sbcl_bind_item, null);
			holder = new ViewHolder();
			holder.nameTv = (TextView) convertView.findViewById(R.id.bluetooth_name_tv);
			holder.idTv = (TextView) convertView.findViewById(R.id.bluetooth_id_tv);
			holder.macTv = (TextView) convertView.findViewById(R.id.bluetooth_mac_tv);
			convertView.setTag(holder);
			
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		BTDevice info = infoList.get(position);
		holder.idTv.setText("设备号："+(position+1));
		holder.nameTv.setText("名称："+info.getName());
		holder.macTv.setText("地址："+info.getMacAddress());
		
		if (position%2==0) {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.table_row_odd));
		}else {
			convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
		}
		
		
		return convertView;
	}
	

	private class ViewHolder{
		
		TextView nameTv;
		TextView idTv;
		TextView macTv;
		
		
	}
	

}
